
package com.mephi.gui;


import javax.swing.ImageIcon;
import javax.swing.JLabel;
import org.apache.log4j.Logger;
import com.mephi.util.PieceColor;
import com.mephi.util.PieceSort;


/**
 * Class represents piece in chess
 * @author GM Mephisto
 * @version 1.0 2011-05-05
 */
public class Piece extends JLabel implements Cloneable
{
	/**
	 * @param pieceSort the sort of pieces to set
	 * @param pieceColor the color of pieces to set
	 * @param icon the image of piece to set
	 */
	public Piece(PieceSort pieceSort, PieceColor pieceColor, ImageIcon icon)
	{
		super(icon);
		logger.debug("icon: " + icon);
		setPieceSort(pieceSort);
		setPieceColor(pieceColor);
		//Image img = icon.getImage().getScaledInstance(icon.getIconWidth(), icon.getIconHeight(), Image.SCALE_FAST);
		//setIcon(new ImageIcon(img));
		setIcon(icon);
	}
	
	/**
	 * @return the pieceSort
	 */
	public PieceSort getPieceSort()
	{
		return pieceSort;
	}
	
	/**
	 * @param pieceSort the pieceSort to set
	 */
	public void setPieceSort(PieceSort pieceSort)
	{
		this.pieceSort = pieceSort;
	}
	
	/**
	 * @return the pieceColor
	 */
	public PieceColor getPieceColor()
	{
		return pieceColor;
	}
	
	/**
	 * @param pieceColor the pieceColor to set
	 */
	public void setPieceColor(PieceColor pieceColor)
	{
		this.pieceColor = pieceColor;
	}
	
	/**
	 * @return the icon
	 */
	public ImageIcon getIcon()
	{
		return icon;
	}
	
	/**
	 * @param icon the icon to set
	 */
	public void setIcon(ImageIcon icon)
	{
		this.icon = icon;
	}
	
	/**
	 * Clears the icon. It sets it to null
	 */
	public void clearIcon()
	{
		setIcon(null);
	}
	
	@Override
	public Object clone()
	{
		Piece result = null;
		try
		{
			result = (Piece) super.clone();
			result.setPieceColor(getPieceColor());
			result.setPieceSort(getPieceSort());
		}
		catch (CloneNotSupportedException e)
		{
			logger.error(e);
		}
		return result;
	}


	private static Logger logger = Logger.getLogger("LOG");
	private static final long serialVersionUID = -5091869882659078845L;
	private PieceSort pieceSort;
	private PieceColor pieceColor;
	private ImageIcon icon;
}
